package terra.model.object.ai;

import java.io.Serializable;

import terra.model.object.LiveObject;
import terra.model.object.NpcObject;
import terra.model.object.action.AbstractAction;
import terra.model.object.action.ActionWait;
import terra.model.object.interfaces.Attacker;

public abstract class AbstractAI implements Serializable {

	public static byte ACTION_WAIT = 0;
	public static byte ACTION_MOVE = 1;
	public static byte ACTION_INTERACT = 2;
	public static byte ACTION_ATTACK = 3;
	public static byte ACTION_DIE = 4;
	public static byte ACTION_FEAR = 5;

	private static final long serialVersionUID = -7521127070256425632L;
	private AbstractAction currentAction, previousAction;
	protected LiveObject owner;
	private boolean aggressive = false;
	private boolean wait = false;
	private boolean canfear = false;
	public int fear = 0;
	protected int maxFear = 2;
	protected transient long lastAttacked = 0;
	protected transient long lastFeared = 0;
	protected transient Attacker lastAttacker;

	public AbstractAI() {
		currentAction = new ActionWait(this, 1000);
	}

	public abstract void update(int delta);

	public abstract void think();

	public void isAttacked(Attacker attacker) {
		lastAttacked = System.currentTimeMillis();
		lastAttacker = attacker;
	}

	public LiveObject getOwner() {
		return owner;
	}

	public void setOwner(NpcObject owner) {
		this.owner = owner;
	}

	public AbstractAction getCurrentAction() {
		return currentAction;
	}

	public void setCurrentAction(AbstractAction currentAction) {
		this.currentAction = currentAction;
	}

	public AbstractAction getPreviousAction() {
		return previousAction;
	}

	public void setPreviousAction(AbstractAction previousAction) {
		this.previousAction = previousAction;
	}

	public boolean isCanfear() {
		return canfear;
	}

	public void setCanfear(boolean canfear) {
		this.canfear = canfear;
	}

	public boolean isAggressive() {
		return aggressive;
	}

	public void setAggressive(boolean aggressive) {
		this.aggressive = aggressive;
	}

	public boolean isWait() {
		return wait;
	}

	public void setWait(boolean wait) {
		this.wait = wait;
	}

}
